package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.pojo.dto.BMIDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    /**
     * 请求地址：/bmi
     * 请求方法：GET
     * 传递数据：height=用户身高   weight=体重
     * 返回响应：String   偏瘦 | 正常 | 微胖 | 该减肥了
     * 测试：http://localhost:8080/bmi?height=1.78&weight=70
     */
    @RequestMapping("/bmi")
    @ResponseBody
    public String bmi(BMIDTO bmidto) {
        Double height = bmidto.getHeight();
        Integer weight = bmidto.getWeight();
        Double bmi = weight / (height * height);

        if (bmi < 18.5) {
            return "偏瘦:"+bmi;
        } else if (bmi > 18.5 && bmi < 24) {
            return "正常:"+bmi;
        } else if (bmi > 24 && bmi < 27) {
            return "微胖:"+bmi;
        }
           return "该减肥了:"+bmi;

    }
}
